package com.scm.erp.framework.config;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.Authentication;

import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Component(value = "successHandler")
public class SuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        System.out.println("ssssssssssssssssss");
        Map<String,Object> msgMap = new HashMap<>();
        msgMap.put("code",0);
        msgMap.put("success",true);
        msgMap.put("error","");
        msgMap.put("message","登陆成功");
        String jsonObject = JSONObject.toJSONString(msgMap);
        System.out.println(jsonObject);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonObject);
    }
}
